package com.chy.blog_server.modular.map.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chy.blog_server.core.util.PageAndParamUtil;
import com.chy.blog_server.core.util.StringUtil;
import com.chy.blog_server.modular.map.entity.MapDistrict;
import com.chy.blog_server.modular.map.entity.MapLog;
import com.chy.blog_server.modular.map.service.impl.MapLogServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述：地图抓取数据日志 开放端controller
 * 作者：chenhuiyan
 * 时间：2025/04/05 22:07
 */
@Controller
@RequestMapping(value = "/map/publicMapLog/")
public class PublicMapLogController {

    @Autowired
    private MapLogServiceImpl mapLogService;

    /**
     * 根据日志编号获取日志列表
     * @return
     */
    @RequestMapping(value = "/mapLogList")
    @ResponseBody
    public synchronized Map<String, Object> mapLogList(HttpServletRequest request){
        Map<String, Object> res = new HashMap<>();
        try{
            Map<String, Object> params = PageAndParamUtil.getParams();
            String logCode = params.get("logCode") + "";
            if(StringUtil.isNull(logCode)){
                res.put("code", 500);
                res.put("msg", "异常：日志编号为空值");
            }else{
                //获取数据列表
                List<MapLog> list = mapLogService.list(
                        new QueryWrapper<MapLog>()
                                .eq("log_code", logCode)
                                .eq("is_show", "0")
                                .orderByAsc("id")
                );
                //把已查询的【是否已回显】更新为是
                if(!list.isEmpty()){
                    for(MapLog mapLog : list){
                        mapLog.setIsShow(1);
                        mapLog.preUpdate();
                    }
                    mapLogService.updateBatchById(list);
                }
                res.put("code", 0);
                res.put("msg", "获取数据成功");
                res.put("count", list.size());
                res.put("data", list);
            }

        }catch (Exception e){
            e.printStackTrace();
            res.put("code", 500);
            res.put("msg", "获取数据失败");
        }
        return res;
    }

}
